set :default_stage, "development"
set :stages, %w(production staging development)
require 'capistrano/ext/multistage'

set(:user, Capistrano::CLI.ui.ask("Orchestra user account: "))

after 'deploy:symlink', 'deploy:database_yml', 'deploy:docroot_symlink', 'deploy:restart'

set :application, "cconnects"      # Can be whatever you want, but probably should be the project name from {SVN\git} repository
set :domain, "orchestra.med.harvard.edu"      # The URL for your app


set :repository,  "svn+ssh://#{user}@orchestra.med.harvard.edu/svn/cbmi/shrimp/trunk"
set :use_sudo, false
set :deploy_via, :export
set :chmod755, "app config db lib public vendor script script/* public/disp*"  	# Some files that will need proper permissions


default_run_options[:pty] = true
# Cap won't work on windows without the above line, see
# http://groups.google.com/group/capistrano/browse_thread/thread/13b029f75b61c09d
# Its OK to leave it true for Linux/Mac

# todo - add ssh key to account and set up public/private key pair for this
# ssh_options[:keys] = ""            # If you are using ssh_keys

role :app, domain
role :web, domain
role :db,  domain, :primary => true

namespace :deploy do
  desc "Copy Orchestras specific {developmnt|staging|production} database.yml into current app's config dir"
  task :database_yml, :roles => :app do
    run "cp  #{deploy_to}/assets/database.yml #{current_path}/config/database.yml"    
  end
  desc "Restarting Passenger / mod_rails by touching tmp/restart.txt"
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "touch #{current_path}/tmp/restart.txt"
  end
  desc "Recreate the symlink of docroot to the current deployed application"
  task :docroot_symlink, :roles => :app do
    run "rm #{deploy_to}/../docroot"
    run "ln -s #{current_path}/public #{deploy_to}/../docroot"
  end
end

